<template>
  <div class="info">
    <!-- 轮播图 -->
    <van-swipe @change="onChange" :autoplay="2000">
      <van-swipe-item v-for="(item, index) in gallery" :key="index">
        <img :src="item.image_url" alt="" />
      </van-swipe-item>
      <template #indicator>
        <div class="custom-indicator">
          {{ current + 1 }}/{{ gallery.length }}
        </div>
      </template>
    </van-swipe>
    <!-- 商品价格、名称 -->
    <div class="txt">
      <p class="price">
        <span class="shop_price">￥{{ shop_price }}</span>
        <del>
          <span class="market_price">价格￥：{{ market_price }}</span>
        </del>
      </p>
      <p class="goods_name">{{ goods_name }}</p>
    </div>
    <!-- 折扣 -->
    <div class="desc">
      <span v-if="prom_type == 0">折扣:无</span>
      <span v-else>折扣:{{ prom_type }}</span>
      <span>{{ comment_count }}人评价</span>
      <span>{{ sales_sum }}人已付款</span>
    </div>
    <!-- 商品属性 -->
    <div class="type">
      <van-collapse v-model="activeNames">
        <van-collapse-item title="选择商品属性" name="1">
          <div class="params">
            <p>颜色</p>
            <van-tag text-color="#666" @click="clickChange($event)"
              >镜面数显款【象牙白】</van-tag
            >
          </div>
        </van-collapse-item>
      </van-collapse>
    </div>
    <!-- 数量 -->
    <div class="num">
      <p>购买数量</p>
      <van-stepper v-model="value" />
    </div>
    <!-- 会员专享 -->
    <div class="vip">
      <van-collapse v-model="activeNames">
        <van-collapse-item title="会员专享价" name="2">
          <div class="dis">
            <p>铜牌会员：<span>9.8折</span></p>
            <p>金牌会员：<span>9.5折</span></p>
            <p>钻石会员：<span>9折</span></p>
          </div>
        </van-collapse-item>
      </van-collapse>
    </div>
    <!-- 评价 -->
    <div class="comment">
      <div class="comment_top">
        <span>商品评价（{{ comment.length }}）</span>
        <span>查看全部></span>
      </div>
      <div class="comment_word" v-for="item in comment" :key="item.comment_id">
        <div class="adv">
          <span><img src="@/assets/imgs/touxiang.png" alt=""/></span>
          <span>{{ item.add_time | formateTime }}</span>
        </div>
        <div class="content">{{ item.content }}</div>
      </div>
    </div>
    <!-- 店铺 -->
    <div class="shop">
      <div class="shop_dec">
        <img src="@/assets/imgs/dianpu.png" alt="" />
        <div class="shop_name">
          <span>{{ store.store_name }}</span>
          <span>共{{ goods.store_count }}件宝贝</span>
        </div>

        <span>
          <router-link :to="'/store/store/' + store.store_id">
            进入店铺</router-link
          ></span
        >
      </div>
      <div class="shop_rang">
        <span>宝贝描述:{{ store.store_desccredit }} <i>高</i> </span>
        <span>卖家服务:{{ store.store_servicecredit }}<i>高</i> </span>
        <span>物流服务:{{ store.store_deliverycredit }}<i>高</i> </span>
      </div>
    </div>
    <div class="shop_info">商品详情</div>
    <div v-html="goods.goods_content" class="shop_img"></div>
    <van-goods-action>
      <van-goods-action-icon icon="chat-o" text="客服" />
      <van-goods-action-icon
        icon="cart-o"
        text="购物车"
        @click="$router.push('/car')"
      />
      <van-goods-action-icon icon="star" text="已收藏" />
      <van-goods-action-button
        type="warning"
        text="加入购物车"
        @click="getaddCarList"
      />
      <van-goods-action-button type="danger" text="立即购买" />
    </van-goods-action>
  </div>
</template>

<script>
export default {
  data() {
    return {
      current: 0,
      activeNames: ["1"],
      value: 1,
      gallery: [],
      market_price: "", // 市场价
      shop_price: "", // 店铺价
      goods_name: "", //商品名称
      comment_count: "", // 评论数
      sales_sum: "0", // 商品销量
      prom_type: "", // 0 没有  1 团购  2 抢购  3 优惠信息
      comment: [], //评论列表
      store: {}, //店铺信息
      goods: {}
    };
  },
  created() {
    this.getGoodInfo();
    console.log(this.value);
  },
  methods: {
    async getGoodInfo() {
      let { data: res } = await this.$axios.get("Goods/goodsInfo", {
        params: { id: this.$route.params.id }
      });
      this.gallery = res.result.gallery;
      this.market_price = res.result.goods.market_price;
      this.shop_price = res.result.goods.shop_price;
      this.goods_name = res.result.goods.goods_name;
      this.comment_count = res.result.goods.comment_count;
      this.sales_sum = res.result.goods.sales_sum;
      this.prom_type = res.result.goods.prom_type;
      this.comment = res.result.comment;
      this.store = res.result.store;
      this.goods = res.result.goods;
    },
    // 添加到购物车
    async getaddCarList() {
      let { data: res } = await this.$axios.get("Cart/addCart", {
        params: {
          goods_id: this.$route.params.id,
          goods_num: this.value,
          unique_id: JSON.parse(sessionStorage.getItem("userinfo")).user_id
        }
      });
      if (res.status !== 1)
        return this.$notify({ type: "danger", message: res.data.msg });
    },

    onChange(index) {
      this.current = index;
    },
    clickChange(e) {
      e.target.style.backgroundColor = "#ff4f02";
      e.target.style.color = "#fff";
    }
  }
};
</script>

<style lang="less" >
.info {
  background-color: #f4f5fa;
  .custom-indicator {
    position: absolute;
    right: 5px;
    bottom: 5px;
    padding: 2px 5px;
    font-size: 12px;
    background: rgba(0, 0, 0, 0.1);
  }
  .van-swipe {
    height: 800px;
    img {
      width: 100%;
      height: 800px;
    }
    .custom-indicator {
      width: 70px;
      font-size: 24px;
      color: #ffffff;
      text-align: center;
      height: 40px;
      line-height: 40px;
      background-color: #000000;
      border-radius: 20px;
      opacity: 0.5;
    }
  }
  .txt {
    padding: 0 60px 29px 25px;
    .price {
      .shop_price {
        color: #fd0000;
        font-size: 44px;
        font-weight: 700;
      }
      del {
        color: #a6a6a6;
        .market_price {
          font-size: 30px;
          margin-left: 19px;
        }
      }
    }
    .goods_name {
      margin-top: 28px;
      font-size: 32px;
      color: #444444;
      line-height: 40px;
      font-weight: 600;
    }
  }
  .desc {
    display: flex;
    margin-bottom: 49px;
    justify-content: space-between;
    padding: 0 60px 29px 25px;
    font-size: 26px;
    color: #a7a7a7;
  }
  .type {
    margin-bottom: 61px;
    .params p {
      margin-bottom: 32px;
    }
    .van-tag {
      height: 60px;
      color: #fff;
      background-color: #ffffff;
      border-radius: 8px;
      border: solid 1px #ccc;
    }
  }
  .num {
    padding: 0 25px;
    margin-bottom: 61px;
    p {
      color: #333333;
      font-size: 28px;
      margin-bottom: 60px;
    }
    .van-stepper {
      height: 50px;
      color: #000000;
      font-size: 30px;
      font-weight: 700;
    }
    .van-stepper__plus::before {
      color: red !important;
    }
  }
  .vip {
    margin-bottom: 20px;
    .dis {
      span {
        color: red;
      }
    }
  }
  .comment {
    padding: 29px 24px 40px;
    height: 272px;
    background-color: #fff;
    overflow: hidden;
    margin-bottom: 20px;
    .comment_top {
      display: flex;
      justify-content: space-between;
      font-size: 28px;
      color: #333333;
      margin-bottom: 30px;
      span:nth-child(2) {
        color: #ff4f02;
      }
    }
    .comment_word {
      display: flex;
      flex-direction: column;
      font-size: 24px;
      color: #999999;
      margin-bottom: 60px;
      .adv {
        display: flex;
        justify-content: space-between;
        margin-bottom: 27px;

        span:nth-child(1) {
          width: 54px;
          height: 54px;
        }
      }
    }
  }
  .shop {
    padding: 30px 24px;
    height: 194px;
    background-color: #fff;
    position: relative;
    .shop_dec {
      display: flex;
      justify-content: space-between;
      span {
        font-size: 28px;
      }
      span:nth-child(3) {
        font-size: 28px;
        padding: 0 20px;
        height: 44px;
        line-height: 42px;
        text-align: center;
        border: 1px solid red;
        color: red;
        border-radius: 22px;
      }
      .shop_name {
        display: flex;
        flex-direction: column;
        position: absolute;
        left: 137px;
        span:nth-child(2) {
          color: #666666;
        }
      }
      img {
        width: 94px;
        height: 94px;
      }
    }
    .shop_rang {
      display: flex;
      justify-content: space-between;
      margin-top: 24px;
      font-size: 28px;
      color: #666666;
      margin-bottom: 20px;
      i {
        font-style: normal;
        font-size: 18px;
        color: #fbfbfb;
        width: 26px;
        height: 26px;
        line-height: 26px;
        text-align: center;
        background-color: #ff0000;
        border-radius: 4px;
      }
    }
  }
  .shop_info {
    height: 88px;
    background-color: #fff;
    line-height: 88px;
    text-align: center;
    font-weight: 700;
    margin-bottom: 20px;
  }
  .shop_img {
    img {
      width: 100%;
    }
  }
}
</style>
